package com.wrench.elevator.tida.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.wrench.elevator.tida.constant.Result;
import com.wrench.elevator.tida.domain.Building;
import com.wrench.elevator.tida.domain.City;
import com.wrench.elevator.tida.domain.District;
import com.wrench.elevator.tida.domain.Page;
import com.wrench.elevator.tida.domain.Province;
import com.wrench.elevator.tida.exception.WrenchException;
import com.wrench.elevator.tida.service.ZZGLService;
import com.wrench.elevator.tida.util.ExcelUtil;
import com.wrench.elevator.tida.util.WrenchUtil;

@Controller
@RequestMapping("/organization_manage")
public class OrganizationManageController {
	private static final Logger logger = LoggerFactory
			.getLogger(OrganizationManageController.class);

	@Resource
	private ZZGLService zZGLService;



	@RequestMapping(value = "/batchCheck")
	public void batchCheck(HttpServletRequest request,
						   HttpServletResponse response, ModelMap map){
		logger.debug("==>**********enter in batchCheck(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String[] ids=WrenchUtil.getParas(request,"id");
		String type=WrenchUtil.getPara(request,"type");
		WrenchException error = null;
		for(String id:ids) {

			try {
				zZGLService.check(id, type);
			} catch (WrenchException e) {
				error = e;
				break;
			}
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "batchCheck success");

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;
		logger.debug("==>**********exit out batchCheck(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

	}

    @RequestMapping(value = "/check", method = RequestMethod.GET)
	public void check(HttpServletRequest request,
                      HttpServletResponse response, ModelMap map){
        logger.debug("==>**********enter in check(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
        String id=WrenchUtil.getPara(request,"id");
        String type=WrenchUtil.getPara(request,"type");
        String telphone=WrenchUtil.getPara(request,"phone");
        WrenchException error=null;
        List<String> new_device_alias = new ArrayList<>();
        List<Map<String, String>> faces_list = new ArrayList<>();
       /* Map<String, String> face = new HashMap<>();
        face.put("face_id", "00062018072411332485353d3b2f39b9c9b5ee3576578c04b7");
        face.put("input_time", "2018-07-24 11:33:24");
        face.put("floor", "3");
        face.put("user_id", "000120180724113319020c8bfac8de160d4c5543b96d1fdede");
        faces_list.add(face);
        new_device_alias.add("bb4f519b24a9537e");
        new_device_alias.add("315cda6824743ce1");*/
        String user_id = null;
        try {
            zZGLService.check(id,type);
            
            user_id= zZGLService.getUseridByTel(telphone);
            new_device_alias = zZGLService.getDeviceAlias(user_id, 0);

            faces_list = zZGLService.getFaceIds(user_id, 0);
            
        } catch (WrenchException e) {
            error=e;
        }
        if (WrenchUtil.hasNull(error)) {
            map.clear();
            map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
            map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
            map.put("message", "check success");

        } else {
            map.clear();
            map.put(Result.RESULT_CODE, error.getResultCode());
            map.put(Result.RESULT_MESSAGE, error.getResultMessage());
        }
        
        if (!WrenchUtil.hasNull(new_device_alias, faces_list)) {

            // 加入新单元
            for (String device_alias : new_device_alias) {
                Map<String, Object> contents = new HashMap<>();
                contents.put("pushCode", "001");
                contents.put("pushMessage", "add face");
                contents.put("faces", faces_list);
                WrenchUtil.pushToJiaoxiang(device_alias, contents);
            }
        }
        
        
        logger.debug("==> response = {}", JSON.toJSON(map));
        WrenchUtil.responseMap(response, map);
        map = null;
        logger.debug("==>**********exit out check(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

    }

	@RequestMapping(value = "/getCheckList", method = RequestMethod.GET)
	public void getCheckList(HttpServletRequest request,
							 HttpServletResponse response, ModelMap map){
		logger.debug("==>**********enter in getProvinceByWuyeId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

		String wuye_id=WrenchUtil.getPara(request,"wuye_id");
		String building_id=WrenchUtil.getPara(request,"building_id");
		String current_page=WrenchUtil.getPara(request,"current_page");
		String limit=WrenchUtil.getPara(request,"limit");
		String[] type=WrenchUtil.getParas(request,"type");
		if(type!=null && type.length==1&&type[0].equals("5")){
			type=new String[]{"0","1","2","3","4"};
		}
		logger.debug("==> params : wuye_id = {} , building_id = {} , type = {} , current_page = {} , limit = {} ",wuye_id,building_id,type,current_page,limit);
		if(null!=type&&type.length>0){
			logger.debug("==> type = =================================> {}", Arrays.toString(type));
		}

		WrenchException error=null;
		Page page=null;

		try {
			page=zZGLService.getCheckList(wuye_id,building_id,type,current_page,limit);
		} catch (WrenchException e) {
			error=e;
		}


		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getCheckList success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;
		logger.debug("==>**********exit out getProvinceByWuyeId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

	}

	@RequestMapping(value = "/getProvinceByWuyeId", method = RequestMethod.GET)
	public void getProvinceByWuyeId(HttpServletRequest request,
									HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getProvinceByWuyeId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

		String wuye_id = WrenchUtil.getPara(request, "wuye_id");

		logger.debug("==> params : wuye_id = {} ", wuye_id);
		List<Province> provinces = null;
		WrenchException error = null;
		try {
			provinces = zZGLService.getProvinceByWuyeId(wuye_id);
		} catch (WrenchException e) {
			error = e;
		}

		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getProvinceByWuyeId success");
			map.put("provinces", provinces);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out getProvinceByWuyeId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

	}

	@RequestMapping(value = "/getDistrictByWuyeId", method = RequestMethod.GET)
	public void getDistrictByWuyeId(HttpServletRequest request,
									HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getDistrictByWuyeId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

		String wuye_id = WrenchUtil.getPara(request, "wuye_id");

		logger.debug("==> params : wuye_id = {} ", wuye_id);
		List<District> districts = null;
		WrenchException error = null;
		try {
			districts = zZGLService.getDistrictByWuyeId(wuye_id);
		} catch (WrenchException e) {
			error = e;
		}

		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getDistrictByWuyeId success");
			map.put("districts", districts);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out getDistrictByWuyeId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

	}

	@RequestMapping(value="/getBuildingInfo", method = RequestMethod.GET)
	public void getBuildingInfo(HttpServletRequest request,
								HttpServletResponse response, ModelMap map){
		logger.debug("==>**********enter in getBuildingInfo(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String building_id=WrenchUtil.getPara(request,"building_id");
        Map building=null;
        WrenchException error=null;
		try {
			building=zZGLService.getBuildingInfo(building_id);
		} catch (WrenchException e) {
			error=e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getBuildingInfo success");
			map.put("building", building);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;
		logger.debug("==>**********exit out getBuildingInfo(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

	}


	@RequestMapping(value = "/getProvinces", method = RequestMethod.GET)
	public void getProvinces(HttpServletRequest request,
							 HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getProvinces(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String wuye_id = WrenchUtil.getPara(request, "wuye_id");
		logger.debug("==> params : wuye_id = {} ", wuye_id);
		List<Province> provinces = null;
		WrenchException error = null;
		try {
			provinces = zZGLService.getProvinces(wuye_id);
		} catch (WrenchException e) {
			// TODO Auto-generated catch block
			error = e;
		}

		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getProvinces success");
			map.put("provinces", provinces);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out getProvinces(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/getCitys", method = RequestMethod.GET)
	public void getCitys(HttpServletRequest request,
						 HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getProvinces(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

		String province_id = WrenchUtil.getPara(request, "province_id");
		String wuye_id = WrenchUtil.getPara(request, "wuye_id");

		logger.debug("==> params :  wuye_id = {} , province_id = {} ", wuye_id,
				province_id);
		List<City> citys = null;
		WrenchException error = null;
		try {
			citys = zZGLService.getCitys(wuye_id, province_id);
		} catch (WrenchException e) {
			// TODO Auto-generated catch block
			error = e;
		}

		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getCitys success");
			map.put("citys", citys);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out getProvinces(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/getDistricts", method = RequestMethod.GET)
	public void getDistricts(HttpServletRequest request,
							 HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getDistricts(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

		String city_id = WrenchUtil.getPara(request, "city_id");
		String wuye_id = WrenchUtil.getPara(request, "wuye_id");

		logger.debug("==> params :  wuye_id = {} , city_id = {}", wuye_id,
				city_id);

		List<District> districts = null;
		WrenchException error = null;
		try {
			districts = zZGLService.getDistricts(wuye_id, city_id);
		} catch (WrenchException e) {
			// TODO Auto-generated catch block
			error = e;
		}

		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getDistricts success");
			map.put("districts", districts);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out getDistricts(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/getBuildings", method = RequestMethod.GET)
	public void getBuildings(HttpServletRequest request,
							 HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getBuildings(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

		String district_id = WrenchUtil.getPara(request, "district_id");

		List<Building> buildings = null;
		WrenchException error = null;
		try {
			buildings = zZGLService.getBuildings(district_id);
		} catch (WrenchException e) {
			// TODO Auto-generated catch block
			error = e;
		}

		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getBuildings success");
			map.put("buildings", buildings);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out getBuildings(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/addBuilding", method = RequestMethod.POST)
	public void addBuilding(HttpServletRequest request,
							HttpServletResponse response, ModelMap map) {

		logger.debug("==>**********enter in addBuilding(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String building_name = WrenchUtil.getPara(request, "building_name");
		String province_id = WrenchUtil.getPara(request, "province_id");
		String province_name = WrenchUtil.getPara(request, "province_name");
		String city_id = WrenchUtil.getPara(request, "city_id");
		String city_name = WrenchUtil.getPara(request, "city_name");
		String district_id = WrenchUtil.getPara(request, "district_id");
		String district_name = WrenchUtil.getPara(request, "district_name");
		String price=WrenchUtil.getPara(request,"price");
		String reg_charge=WrenchUtil.getPara(request,"reg_charge");
		String is_check=WrenchUtil.getPara(request,"is_check");
		String building_type=WrenchUtil.getPara(request,"building_type");
		String chengti_type=WrenchUtil.getPara(request,"chengti_type");
		String reg_gift=WrenchUtil.getPara(request,"reg_gift");


		logger.debug(
				"==> params: building_name = {} , province_id = {}, province_name = {} , city_id = {} , city_name = {} , district_id = {} , district_name = {} , price = {} , reg_charge = {} , is_check = {} , building_type = {}  , chengti_type = {} , reg_gift = {} ",
				building_name, province_id, province_name, city_id, city_name,
				district_id, district_name,price,reg_charge,is_check,building_type,chengti_type,reg_gift);
		WrenchException error = null;
		try {
			zZGLService.addBuilding(building_name, province_id, province_name,
					city_id, city_name, district_id, district_name,price,reg_charge,is_check,building_type,chengti_type,reg_gift);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "addBuilding success");

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out addBuilding(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}


    @RequestMapping(value = "alterBuilding", method = RequestMethod.POST)
    public void alterBuilding(HttpServletRequest request,
                            HttpServletResponse response, ModelMap map) {

        logger.debug("==>**********enter in addBuilding(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
        String building_name = WrenchUtil.getPara(request, "building_name");

        String price=WrenchUtil.getPara(request,"price");
        String reg_charge=WrenchUtil.getPara(request,"reg_charge");
        String is_check=WrenchUtil.getPara(request,"is_check");
        String building_type=WrenchUtil.getPara(request,"building_type");
        String chengti_type=WrenchUtil.getPara(request,"chengti_type");
        String reg_gift=WrenchUtil.getPara(request,"reg_gift");
        String building_id=WrenchUtil.getPara(request,"building_id");


        logger.debug(
                "==> params: building_id = {}， building_name = {} ,, price = {} , reg_charge = {} , is_check = {} , building_type = {}  , chengti_type = {} , reg_gift = {} ",
                building_id,building_name, price,reg_charge,is_check,building_type,chengti_type,reg_gift);
        WrenchException error = null;
        try {
            zZGLService.alterBuilding(building_id,building_name,price,reg_charge,is_check,building_type,chengti_type,reg_gift);
        } catch (WrenchException e) {
            error = e;
        }
        if (WrenchUtil.hasNull(error)) {
            map.clear();
            map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
            map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
            map.put("message", "alterBuilding success");

        } else {
            map.clear();
            map.put(Result.RESULT_CODE, error.getResultCode());
            map.put(Result.RESULT_MESSAGE, error.getResultMessage());
        }
        logger.debug("==> response = {}", JSON.toJSON(map));
        WrenchUtil.responseMap(response, map);
        map = null;

        logger.debug("==>**********exit out addBuilding(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
    }


    @RequestMapping(value = "/batchInputUser", method = RequestMethod.POST)
	public void batchInputUser(HttpServletRequest request,
							   HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in batchInputUser(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String danyuan_id = WrenchUtil.getPara(request, "danyuan_id");
		MultipartFile file = WrenchUtil.getFile(request, "file");
		String[] keys = { "loucen", "menpaihao", "user_tel", "balance" };
		logger.debug("==> params : danyuan_id = {} , file = {} ", danyuan_id,
				file);
		WrenchException error=null;
		Map<String, String>[] value = null;
		try {
			value = ExcelUtil.analyseExcel(file.getInputStream(), keys);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		t:
		for (Map<String, String> m : value) {
			try {
				zZGLService.inputUser(danyuan_id, m.get("loucen"),
						m.get("menpaihao"), m.get("user_tel"),
						m.get("balance"), map);
			} catch (WrenchException e) {
				// TODO Auto-generated catch block
				error = e;
				break t;
			}
		}
		if (WrenchUtil.hasNull(error)) {

			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "inputUser success");
		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}

		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;
		logger.debug("==>**********exit out batchInputUser(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/inputUser", method = RequestMethod.POST)
	public void inputUser(HttpServletRequest request,
						  HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in inputUser(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String danyuan_id = WrenchUtil.getPara(request, "danyuan_id");
		String loucen = WrenchUtil.getPara(request, "loucen");
		String menpaihao = WrenchUtil.getPara(request, "menpaihao");
		String user_tel = WrenchUtil.getPara(request, "user_tel");
		String balance = WrenchUtil.getPara(request, "balance");
		logger.debug(
				"==> params : danyuan_id = {} , loucen = {} , menpaihao = {} , user_tel = {} , balance = {}  ",
				danyuan_id, loucen, menpaihao, user_tel, balance);

		WrenchException error = null;
		try {
			zZGLService.inputUser(danyuan_id, loucen, menpaihao, user_tel,
					balance, map);
		} catch (WrenchException e) {
			// TODO Auto-generated catch block
			error = e;
		}

		if (WrenchUtil.hasNull(error)) {
			Object flag = map.get("flag");
			if ("SUCCESS".equals(flag)) {
				map.clear();
				map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
				map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
				map.put("message", "inputUser success");
			} else {
				map.clear();
				map.put(Result.RESULT_CODE, Result.OTHER_ERROR_CODE);
				map.put(Result.RESULT_MESSAGE, Result.OTHER_ERROR_MESSAGE);

			}

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out inputUser(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}


	@RequestMapping(value = "/queryUserByBuildingId", method = RequestMethod.GET)
	public void queryUserByBuildingId(HttpServletRequest request,
									  HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in queryUserByBuildingId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String building_id = WrenchUtil.getPara(request, "building_id");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String type=WrenchUtil.getPara(request,"type");
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.queryUserByBuildingId(building_id, current_page,
					limit);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "queryUserByBuildingId  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
			WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelUserList(page.getList(),response);
		map = null;

		logger.debug("==>**********exit out queryUserByBuildingId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/queryUserByProvinceId", method = RequestMethod.GET)
	public void queryUserByProvinceId(HttpServletRequest request,
									  HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in queryUserByProvinceId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String province_id = WrenchUtil.getPara(request, "province_id");
		String wuye_id=WrenchUtil.getPara(request,"wuye_id");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String type=WrenchUtil.getPara(request,"type");
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.queryUserByProvinceId(province_id,wuye_id, current_page,
					limit);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "queryUserByProvinceId  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
			WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelUserList(page.getList(),response);
		map = null;

		logger.debug("==>**********exit out queryUserByProvinceId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}



	@RequestMapping(value = "/queryUserByDistrictId", method = RequestMethod.GET)
	public void queryUserByDistrictId(HttpServletRequest request,
								  HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in queryUserByDistrictId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String district_id = WrenchUtil.getPara(request, "district_id");
		String wuye_id=WrenchUtil.getPara(request,"wuye_id");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String type=WrenchUtil.getPara(request,"type");
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.queryUserByDistrictId(district_id,wuye_id, current_page,
					limit);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "queryUserByDistrictId  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
			WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelUserList(page.getList(),response);
		map = null;

		logger.debug("==>**********exit out queryUserByDistrictId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/queryUserByCityId", method = RequestMethod.GET)
	public void queryUserByCityId(HttpServletRequest request,
									  HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in queryUserByCityId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String city_id = WrenchUtil.getPara(request, "city_id");
		String wuye_id=WrenchUtil.getPara(request,"wuye_id");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String type=WrenchUtil.getPara(request,"type");
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.queryUserByCityId(city_id,wuye_id, current_page,
					limit);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "queryUserByCityId  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
			WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelUserList(page.getList(),response);		map = null;

		logger.debug("==>**********exit out queryUserByCityId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}



	@RequestMapping(value = "/queryUserByDanyuanId", method = RequestMethod.GET)
	public void queryUserByDanyuanId(HttpServletRequest request,
									 HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in queryUserByDanyuanId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String danyuan_id = WrenchUtil.getPara(request, "danyuan_id");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String type=WrenchUtil.getPara(request,"type");
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.queryUserByDanyuanId(danyuan_id, current_page,
					limit);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "queryUserByDanyuanId  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
			WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelUserList(page.getList(),response);
		map = null;

		logger.debug("==>**********exit out queryUserByDanyuanId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/updateUser", method = RequestMethod.POST)
	public void updateUser(HttpServletRequest request,
						   HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in updateUser(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String loucen = WrenchUtil.getPara(request, "loucen");
		String menpaihao = WrenchUtil.getPara(request, "menpaihao");
		String user_id = WrenchUtil.getPara(request, "user_id");
		String balance = WrenchUtil.getPara(request, "balance");

		logger.debug(
				"==> params: loucen = {} , menpaihao = {} , user_id = {} , balance = {} ",
				loucen, menpaihao, user_id, balance);

		WrenchException error = null;
		try {
			zZGLService.updateUser(loucen, menpaihao, user_id, balance);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "updateUser success");

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		WrenchUtil.responseMap(response, map);
		map = null;

		logger.debug("==>**********exit out updateUser(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

	}

	@RequestMapping(value = "/queryUserByTelAndWuyeId", method = RequestMethod.GET)
	public void queryUserByTelAndWuyeId(HttpServletRequest request,
										HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in queryUserByTelAndWuyeId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String wuye_id = WrenchUtil.getPara(request, "wuye_id");
		String user_tel = WrenchUtil.getPara(request, "user_tel");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String type=WrenchUtil.getPara(request,"type");
		logger.debug(
				"==> params : wuye_id = {} , user_tel = {} , current_page = {} , limit = {} ",
				wuye_id, user_tel, current_page, limit);
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.queryUserByTelAndWuyeId(wuye_id, user_tel,
					current_page, limit);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "queryUserByTelAndWuyeId  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
			WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelUserList(page.getList(),response);
		map = null;

		logger.debug("==>**********exit out queryUserByTelAndWuyeId(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/getDetails", method = RequestMethod.GET)
	public void getDetails(HttpServletRequest request,
						   HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getDetails(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String value = WrenchUtil.getPara(request, "value");
		switch (value) {
			case "chengti":
				try {
					request.getRequestDispatcher("getChengtiDetails").forward(request, response);
				} catch (ServletException | IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				break;
			case "chongzhi":
				try {
					request.getRequestDispatcher("getChongzhiDetails").forward(request, response);
				} catch (ServletException | IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				break;
			case "flow":
				try {
					request.getRequestDispatcher("getFlowDetails").forward(request, response);
				} catch (ServletException | IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				break;

			default:
				break;
		}
		logger.debug("==>**********exit out getDetails(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");

	}

	@RequestMapping(value = "/getChongzhiDetails", method = RequestMethod.GET)
	public void getChongzhiDetails(HttpServletRequest request,
								   HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getChongzhiDetails(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String user_id = WrenchUtil.getPara(request, "user_id");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String start_date = WrenchUtil.getPara(request, "start_date").replace("-", "");
		String end_date = WrenchUtil.getPara(request, "end_date").replace("-", "");
		String type=WrenchUtil.getPara(request,"type");
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.getChongzhiDetails(user_id, current_page, limit,
					start_date, end_date);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getChongzhiDetails  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
			WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelFlowList(page.getList(),response);
		map = null;
		logger.debug("==>**********exit out getChongzhiDetails(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/getChengtiDetails", method = RequestMethod.GET)
	public void getChengtiDetails(HttpServletRequest request,
								  HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getChengtiDetails(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String user_id = WrenchUtil.getPara(request, "user_id");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String start_date = WrenchUtil.getPara(request, "start_date").replace("-", "");
		String end_date = WrenchUtil.getPara(request, "end_date").replace("-", "");
		String type=WrenchUtil.getPara(request,"type");
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.getChengtiDetails(user_id, current_page, limit,
					start_date, end_date);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getChengtiDetails  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
		WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelFlowList(page.getList(),response);
		map = null;
		logger.debug("==>**********exit out getChengtiDetails(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}

	@RequestMapping(value = "/getFlowDetails", method = RequestMethod.GET)
	public void getFlowDetails(HttpServletRequest request,
							   HttpServletResponse response, ModelMap map) {
		logger.debug("==>**********enter in getFlowDetails(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
		String user_id = WrenchUtil.getPara(request, "user_id");
		String current_page = WrenchUtil.getPara(request, "current_page");
		String limit = WrenchUtil.getPara(request, "limit");
		String start_date = WrenchUtil.getPara(request, "start_date").replace("-", "");
		String end_date = WrenchUtil.getPara(request, "end_date").replace("-", "");
		String type=WrenchUtil.getPara(request,"type");
		Page page = null;
		WrenchException error = null;
		try {
			page = zZGLService.getFlowDetails(user_id, current_page, limit,
					start_date, end_date);
		} catch (WrenchException e) {
			error = e;
		}
		if (WrenchUtil.hasNull(error)) {
			map.clear();
			map.put(Result.RESULT_CODE, Result.SUCCESS_CODE);
			map.put(Result.RESULT_MESSAGE, Result.SUCCESS_MESSAGE);
			map.put("message", "getFlowDetails  success");
			map.put("page", page);

		} else {
			map.clear();
			map.put(Result.RESULT_CODE, error.getResultCode());
			map.put(Result.RESULT_MESSAGE, error.getResultMessage());
		}
		logger.debug("==> response = {}", JSON.toJSON(map));
		if("0".equals(type))
			WrenchUtil.responseMap(response, map);
		else
			ExcelUtil.outputExcelFlowList(page.getList(),response);
		map = null;
		logger.debug("==>**********exit out getFlowDetails(HttpServletRequest request, HttpServletResponse response, ModelMap map)**********");
	}
}
